package cn.melon.mod.library;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * LibraryInfo.java. 图书馆图书管理实体类
 * 
 * @author PJY
 * @date Sept 5, 2016
 */
public class LibraryBooksInfo {

    /**
     * 书名
     */
    private String bookName;                       
    /**
     * 书编号 
     */
    private String bookID;                         
    /**
     * 出版社
     */
    private String publisher;                      
    /**
     * 作者
     */
    private String author;                         
    /**
     * 是否可借（ 0为否，1为是）
     */
    private String loanable;                       
    /**
     * 借书人
     */
    private String borrowStudent;                  
    /**
     * 借书时间
     */
    private String borrowDate;                     
    /**
     * 应还书时间
     */
    private String DDL;                           
    /**
     * 已还书时间
     */
    private String returnDate;                     


    /**
     * 设置图书信息
     * @param jInfo 图书对象的json字符串
     * @return 返回图书对象
     * @throws JSONException json解析错误
     */
    public static LibraryBooksInfo toInfo(JSONObject jInfo) throws JSONException {

        LibraryBooksInfo libraryBooksInfo = new LibraryBooksInfo();
        libraryBooksInfo.setBookName(jInfo.getString("bookName"));
        libraryBooksInfo.setBookID(jInfo.getString("bookID"));
        libraryBooksInfo.setPublisher(jInfo.getString("publisher"));
        libraryBooksInfo.setAuthor(jInfo.getString("author"));
        libraryBooksInfo.setLoanable(jInfo.getString("loanable"));
        libraryBooksInfo.setBorrowStudent(jInfo.getString("borrowStudent"));
        libraryBooksInfo.setBorrowDate(jInfo.getString("borrowDate"));
        libraryBooksInfo.setDDL(jInfo.getString("DDL"));
        libraryBooksInfo.setReturnDate(jInfo.getString("returnDate"));

        return libraryBooksInfo;
    }

    /**
     * 转化为JSON字符串
     * @return 返回当前对象对应的json字符串
     * @throws JSONException json添加错误
     */
    public JSONObject toJSON() throws JSONException {
        JSONObject jInfo = new JSONObject();
        jInfo.put("bookName", getBookName());
        jInfo.put("bookID", getBookID());
        jInfo.put("publisher", getPublisher());
        jInfo.put("author", getAuthor());
        jInfo.put("loanable", getLoanable());
        jInfo.put("borrowStudent", getBorrowStudent());
        jInfo.put("borrowDate", getBorrowDate());
        jInfo.put("DDL", getDDL());
        jInfo.put("returnDate", getReturnDate());

        return jInfo;
    }

    /**
     * 图书信息
     * @param bookName       书名
     * @param bookID         书编号
     * @param publisher      出版社
     * @param author         责任者
     * @param loanable       是否可借
     * @param borrowStudent  借书人
     * @param borrowDate     借书日期
     * @param DDL            应还日期
     * @param returnDate     实际归还日期
     */
    public LibraryBooksInfo(String bookName, String bookID, String publisher, String author, String loanable,
            String borrowStudent, String borrowDate, String DDL, String returnDate) {
        this.bookName = bookName;
        this.bookID = bookID;
        this.publisher = publisher;
        this.author = author;
        this.loanable = loanable;
        this.borrowStudent = borrowStudent;
        this.borrowDate = borrowDate;
        this.DDL = DDL;
        this.returnDate = returnDate;
    }

    public LibraryBooksInfo() {
    }

    public String getBookName() {
        return bookName;
    }

    public void setBookName(String bookName) {
        this.bookName = bookName;
    }

    public String getBookID() {
        return bookID;
    }

    public void setBookID(String bookID) {
        this.bookID = bookID;
    }

    public String getPublisher() {
        return publisher;
    }

    public void setPublisher(String publisher) {
        this.publisher = publisher;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public String getLoanable() {
        return loanable;
    }

    public void setLoanable(String loanable) {
        this.loanable = loanable;
    }

    public String getBorrowStudent() {
        return borrowStudent;
    }

    public void setBorrowStudent(String borrowStudent) {
        this.borrowStudent = borrowStudent;
    }

    public String getBorrowDate() {
        return borrowDate;
    }

    public void setBorrowDate(String borrowDate) {
        this.borrowDate = borrowDate;
    }

    public String getDDL() {
        return DDL;
    }

    public void setDDL(String dDL) {
        DDL = dDL;
    }

    public String getReturnDate() {
        return returnDate;
    }

    public void setReturnDate(String returnDate) {
        this.returnDate = returnDate;
    }

}
